home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / test / c / tcaptest < prev    next >
Text File  |  1992-09-09  |  3KB  |  97 lines

  1. /* tcaptest.c (c) Copyright 1990 H.Rogers */
  2.  
  3. /* This program tests the termcap(3) library routines. */
  4. /* For full information on termcap, read the appropriate entries
  5.  * in sections 3 and 5 of the UNIX Programmer's Manual. */
  6.  
  7. #include <stdio.h>            /* standard I/O and UNIX */
  8. #include <stdlib.h>            /* standard library */
  9.  
  10. #include "termcap.h"            /* screen handling functions */
  11.  
  12. #ifndef EMULATE
  13. #include "termio.h"            /* terminal I/O */
  14.  
  15. extern int ioctl(int,int,void *);
  16. #endif
  17.  
  18. short ospeed;                /* terminal speed */
  19. char PC,*BC,*UP;            /* terminal capabilities */
  20. static char *CL,*CM,*SO,*SE;
  21. static int LI,CO;
  22.  
  23. static char tent[1024];         /* terminal entry buffer */
  24. static char tbuf[512];            /* terminal capabilities buffer */
  25. static char *tbufp;            /* index pointer for '' */
  26.  
  27. int out(char);                /* single character output function */
  28.  
  29. int main()
  30. {
  31. int i,j;                /* general purpose */
  32. int fd;                 /* file descriptor of tty */
  33. #ifndef EMULATE
  34. struct termio t[1];            /* terminal I/O control structure */
  35. #endif
  36.  
  37. if (tgetent(tent,getenv("TERM")) < 1)    /* get terminal entry */
  38.   {
  39.   fprintf(stderr,"tcaptest: tgetent returned < 1 (have you set TERM ?)\n");
  40.   exit(1);
  41.   }
  42.  
  43. tbufp = tbuf;                /* initialise index pointer */
  44.  
  45. if (tgetflag("pc"))            /* get 'pc' capability */
  46.   PC = *tgetstr("pc",&tbufp);        /* PC is a library variable */
  47. else
  48.   PC = '\000';                /* defaults to '\000' */
  49. if (tgetflag("bs"))            /* get 'bs' capability */
  50.   BC = "\010";                /* 'bs' capability => BC = "\010" */
  51. else
  52.   BC = tgetstr("bc",&tbufp);        /* get 'bc' capability since no 'bs' */
  53. UP = tgetstr("up",&tbufp);        /* get 'up' - move cursor up */
  54. CL = tgetstr("cl",&tbufp);        /* get 'cl' - clear screen */
  55. CM = tgetstr("cm",&tbufp);        /* get 'cm' - cursor motion */
  56. SO = tgetstr("so",&tbufp);        /* get 'so' - start 'standout' mode */
  57. SE = tgetstr("se",&tbufp);        /* get 'se' - end 'standout' mode */
  58.  
  59. LI = tgetnum("li");            /* get 'li' - number of lines */
  60. CO = tgetnum("co");            /* get 'co' - number of columns */
  61.  
  62. /* now check all capabilities were present */
  63.  
  64. if ((!BC) || (!UP) || (!CL) || (!CM) || (!SO) || (!SE))
  65.   {
  66.   fputs("tcaptest: terminal must have bc, up, cl, cm, so, and se\n",stderr);
  67.   exit(1);
  68.   }
  69.  
  70. #ifndef EMULATE
  71. fd = fileno(stdout);            /* get terminal file descriptor */
  72. ioctl(fd,TCGETA,t);            /* get terminal I/O control */
  73. ospeed = t->c_cflag & CBAUD;        /* set ospeed to baud rate */
  74. t->c_oflag &= (~XTABS);         /* turn off XTABS for termcap */
  75. ioctl(fd,TCSETA,t);            /* set terminal I/O control */
  76. #endif
  77.  
  78. tputs(CL,0,out);            /* clear screen */
  79. for(i = 0; i < LI - 2; i++)
  80.   {
  81.   j = (i<<1); if (j > CO - 6) j = CO - 6;
  82.   tputs(tgoto(CM,j,i),0,out);        /* goto ((i << 1), i) */
  83.   fputs("Hi..",stdout);         /* print "Hi.." */
  84.   tputs(SO,0,out);            /* start 'standout' mode */
  85.   j = CO - 6 - (i<<1); if (j < 0) j = 0;
  86.   tputs(tgoto(CM,j,i),0,out);        /* goto (74 - (i << 1), i) */
  87.   fputs("Hi..",stdout);         /* print "Hi.." */
  88.   tputs(SE,0,out);            /* end 'standout' mode */
  89.   }
  90. printf("\ncolumns: %d\tlines: %d\n",CO,LI);
  91. }
  92.  
  93. int out(char c)             /* write character to terminal */
  94. {
  95. return(putchar(c));            /* use putchar() */
  96. }
  97.